package com.sk.tools.excel.reader;

import com.sk.tools.excel.meta.model.ExcelMeta;
import com.sk.tools.excel.handler.RecordHandler;
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;

;

public class PoiStreamReader implements Reader {
    private XSSFWorkbook workbook;
    @Override
    public void read(InputStream in, RecordHandler handler, ExcelMeta ExcelConfigMeta) {
        try {
            workbook = new XSSFWorkbook(in);
            ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(workbook.getPackage());
            new XSSFSheetXMLHandler(workbook.getStylesSource(), strings, createSheetContentsHandler(), false);
            workbook.close();
        } catch (IOException | SAXException e) {
            e.printStackTrace();
        }


    }

    private XSSFSheetXMLHandler.SheetContentsHandler createSheetContentsHandler() {
        return new XSSFSheetXMLHandler.SheetContentsHandler(){
            @Override
            public void startRow(int i) {

            }

            @Override
            public void endRow(int i) {

            }

            @Override
            public void cell(String s, String s1, XSSFComment xssfComment) {

            }
        };
    }
}
